/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import dayjs from 'dayjs'

const DATE_TIME_FORMAT_MILL = 'YYYY-MM-DD HH:mm:ss.SSS'
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
const DATE_FORMAT = 'YYYY-MM-DD'

export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
  return dayjs(date).format(format)
}

export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string {
  return dayjs(date).format(format)
}

export function formatMilliseconds(milliseconds: number): string {
  // 使用 dayjs 格式化日期和时间
  // 格式为 'YYYY-MM-DD HH:mm:ss.SSS'，SSS 表示毫秒
  return dayjs(milliseconds).format(DATE_TIME_FORMAT_MILL)
}

export const dateUtil = dayjs
